package net.vsame.url2sql.domain;

import java.util.HashMap;
import java.util.Map;

import net.vsame.url2sql.helper.TypeConvertHelper;

public class Model extends HashMap<String, Object>{

	private static final long serialVersionUID = 1L;
	
	public Model(){
	}
	
	public Model(Map<String, Object> map) {
		this.putAll(map);
	}

	public static Model get(){
		return new Model();
	}
	
	public Model add(String key, Object value){
		this.put(key, value);
		return this;
	}
	public <T> T getType(Class<T> clazz, String key){
		return TypeConvertHelper.parseType(clazz, get(key));
	}
	public Short getShort(String key){
		return getType(Short.class, key);
	}
	public Integer getInt(String key){
		return getType(Integer.class, key);
	}
	public Long getLong(String key){
		return getType(Long.class, key);
	}
	public Float getFloat(String key){
		return getType(Float.class, key);
	}
	public Double getDouble(String key){
		return getType(Double.class, key);
	}

	public static void main(String[] args) {
		Model m = Model.get().add("a", "123.32").add("b", "3");
		System.out.println(m.getDouble("a"));
		System.out.println(m.getFloat("a"));
		System.out.println(m.getInt("b"));
		System.out.println(m.getLong("b"));
	}
	
}
